export const registerInterceptor = () => {
    const methods = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];
    methods.forEach(method => {
        uni.addInterceptor(method, {
            invoke(args) {
				console.log(`${method}方法被调用`)
                const whiteList = ["/pages/index/index", "/pages/login/login"]; // 不需要登录的页面列表
                const targetPath = args.url.split("?")[0]; // 获取目标路径
				const {from=''} = args;
				 console.log('targetPath======',targetPath);
                // 页面不在白名单内，需要判断是否有登录的token
                if (!whiteList.includes(targetPath)) {
                  const token = uni.getStorageSync("token");
				  console.log('args======',args);
                  if (!token) {
                    // 跳转到登录页，并携带原始跳转路径
					uni.redirectTo({
					  url: `/pages/login/login?redirect=${encodeURIComponent(args.url)}&from=${from}`,
					});
                    return false; // 取消原始跳转
                  }
                }
                return args; // 放行跳转
              },
              fail(err) {
                console.log("拦截器捕获跳转失败:", err);
              },
        })  
    })
}